<template>
  <div>

    <el-form>
      <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item>
            <el-input v-model="formFileds.text"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="2">
          <el-form-item>
            <el-button type="primary" @click="onSubmit">查询
            </el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <!--表格内容-->
    <el-table ref="goodList" :data="tableData" style="width: 100%; margin-bottom: 5px;" border stripe highlight-current-row
      :default-sort="{prop: 'date', order: 'descending'}" @row-click="handleRowClick"
      @select-all="handleCheckedAllAndCheckedNone" @select="handleCheckedAllAndCheckedNone"
      :header-cell-style="{textAlign:'center'}" :cell-style="{textAlign:'center'}">
      <el-table-column type="selection" fixed="left"></el-table-column>
      <el-table-column property="name" label="拍品名称"> </el-table-column>
      <el-table-column property="type" label="拍品类型"> </el-table-column>
      <el-table-column property="goodProvince" label="拍品所在地(省)" width="150"> </el-table-column>
      <el-table-column property="goodCity" label="拍品所在地(市)" width="150"> </el-table-column>
      <el-table-column property="sellerProvince" label="卖家所在地(省)" width="150"> </el-table-column>
      <el-table-column property="sellerCity" label="卖家所在地(市)" width="150"> </el-table-column>
      <el-table-column property="describe" label="拍品描述"> </el-table-column>
      <el-table-column  label="图片">
        <template>
          <el-link @click="photo()">点击查看</el-link>
        </template>
      </el-table-column>
      <el-table-column property="company" label="联系人"> </el-table-column>
      <el-table-column property="tel" label="联系电话" width="150"> </el-table-column>
      <el-table-column property="date" label="征集时间" width="150"> </el-table-column>
      <el-table-column property="touch" label="是否取得联系" width="150"> </el-table-column>
      <el-table-column property="state" label="商品状态"> </el-table-column>
      <el-table-column label="操作" fixed="right" width="300">
        <template slot-scope="scope">
          <el-button circle icon="el-icon-edit-outline" type="primary" title="编辑" size="small"
            @click="rowEdit(scope.$index, scope.row)"></el-button>
          <el-button circle icon="el-icon-phone-outline" type="success" title="已联系" size="small"></el-button>
          <el-button circle icon="el-icon-check" type="success" title="上架" size="small"></el-button>
          <el-button circle icon="el-icon-close" type="warning" title="拒收" size="small"></el-button>
          <el-button circle icon="el-icon-delete" type="danger" title="删除" size="small"
            @click="rowDel(scope.$index, scope.row, $event);"></el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--分页-->
    <el-pagination :page-sizes="[10, 20, 30, 40,100]" :page-size="10" :total="100"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

    <!-- 增加-弹出层 -->
    <GoodEdit ref="goodEditref" v-if="goodsEditShow" :goodsEditShow="goodsEditShow" :recored="formFileds"
      @dialogClose="dialogClose"></GoodEdit>
    <Photo v-if="photoShow" :photoShow="photoShow" @dialogClose="dialogClose"></Photo>

  </div>
</template>
    
<script>
import GoodEdit from './goodEdit.vue';
import Photo from './photo.vue';
export default {
  name: "attractGoodsManage",
  components: {
    GoodEdit,
    Photo
  },
  data () {
    return {
      formFileds: {
      },
      tableData: [
        {
          id: 0,
          name: '桑塔纳',
          type: '机动车',
          goodProvince: '辽宁',
          goodCity: '沈阳',
          sellerProvince: '辽宁',
          sellerCity: '阜新',
          describe: '测试',
          company: '某公司',
          tel: '13377771111',
          date: '2016-05-02',
          touch: '是',
          state: '沟通中',
        },
      ],
      goodsEditShow: false,
      photoShow: false,
    }
  },
  methods: {

    handleRowClick (row, event, column) {

      // 仅选中当前行
      this.setCurRowChecked(row);
    },
    handleCheckedAllAndCheckedNone (selection) {

      // 当前选中仅一行时操作-（当前表格行高亮）
      1 != selection.length && this.$refs.goodList.setCurrentRow();
    },
    dialogClose () {

      this.goodsEditShow = false;
      this.photoShow = false;
    },
    rowEdit (index, row) {
      //  console.log(1111)
      // this.$refs.detailRef.handleEdit('qqqq')

      //当前选中行
      this.formFileds = row;
      this.goodsEditShow = true;
    },

    rowDel (index, row, event) {

      // 让当前删除按钮失焦
      event.target.blur();

      this.$confirm('确定要删除当前行吗？', '删除', {
        comfirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(() => {

        this.tableData.splice(row.id, 1);
        this.$message.success('删除成功');
        return false;
      });
    },
    // 选中当前行-当前行的复选框被勾选
    setCurRowChecked (row) {

      this.$refs.goodList.clearSelection();
      this.$refs.goodList.toggleRowSelection(row);
    },
    photo(){
      this.photoShow = true;
    }
  }
}
</script>
    
<style scoped lang="less">
.el-form {
  padding: 0 10px;
}

.el-date-editor {
  width: 100% !important;
}
</style>
    